from common.auto_adb import auto_adb
from common import config
import time
import random

adb = auto_adb()
adb.test_device()
config = config.open_accordant_config()


def next_page():
    """
    翻到下一页
    :return:
    """
    cmd = 'shell input swipe {x1} {y1} {x2} {y2} {duration}'.format(
        x1=config['center_point']['x'],
        y1=config['center_point']['y']+config['center_point']['ry'],
        x2=config['center_point']['x'],
        y2=config['center_point']['y'],
        duration=200
    )
    # cmd = 'shell input tap {x} {y}'.format(
    #     x=650 + _random_bias(10),
    #     y=610 + _random_bias(10)
    # )

    adb.run(cmd)
    time.sleep(1.5)


def _random_bias(num):
    """
    random bias
    :param num:
    :return:
    """
    return random.randint(-num, num)

def thumbs_up():
    """
    点赞
    :return:
    """
    # 抖音
    # cmd = 'shell input tap {x} {y}'.format(
    #     x=660 + _random_bias(10),
    #     y=520 + _random_bias(10)
    # )
    # 快手
    cmd = 'shell input tap {x} {y}'.format(
        x=660 + _random_bias(10),
        y=740 + _random_bias(10)
    )
    adb.run(cmd)
    time.sleep(0.5)

while True:
    next_page()
    thumbs_up()
